package com.astrob.model;

import android.content.Context;

import com.astrob.naviframe.Start;

import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;

public class FavoriteData implements Serializable {
	private static final long serialVersionUID = 1L;
	public double lon;
	public double lat;
	public int icon; //1 为基数 //如果有对应照片，则为8 
	public int eid;  // eid已无用，如果有对应照片，则为拍摄照片到地图中心的距离        
	public String name = "";
	public String address = "";
	public String phoneNum = "";
	public String note = "";
	public int sound; //sound已无用， 如果有对应照片，则为拍摄照片的方向  
	public long currentTimeMillis;
	public String strExInfo; //如果有对应照片，则为照片路径
	public String countryID = "";
	public String pcode = "";

	/*
	0: 表示和服务器已经同步了	
	1:	新增点（还未上传至服务器）	
	2:	处于更改状态（该点曾经提交过，但本次修改还未提交）
	3:	处于删除状态
	*/
	
	public int action;
	private String uuid;
	
	public boolean isHotel() {
		if (pcode.length() < 1)
			return false;

		if (countryID.length() > 1 && countryID.compareToIgnoreCase("twn") == 0) {
			String strPcodeh = "P951P952P953P954";
			if (strPcodeh.contains(pcode)) {
				return true;
			}
		} else {
			String strPcodeh = "P441";
			if (strPcodeh.contains(pcode)) {
				return true;
			}
		}

		return false;
	}

	public void revert(){
		name = "";
		address = "";
		phoneNum = "";
		note = "";
		lon = 180.0;
		lat = 90.0;
		icon = -1;
		sound = 1;
		eid = 0;
		uuid = null;
		action = 1;
		strExInfo = "";
		countryID = "";
		pcode = "";
	}

	public boolean isEclipse() {
		if (action == 3) {
			return true;
		}
		return false;
	}

	public String getUuid() {
		return uuid;
	}

	public void setUuid(String uuid) {
		this.uuid = uuid;
	}

	public FavoriteData() {
		revert();
	}

	public FavoriteData(String name) {
		revert();		
	}

	public FavoriteData(int action) {
		revert();
		this.action = action;
	}

	public void playSound(Context context) {
		if (getSound().length() <= 0) {
			return;
		}	
//		Start.playWavFile(getSound());
	}

	public LonLat getLl() {
		return new LonLat(lon, lat);
	}

	public void setLl(LonLat pos) {
		lon = pos.GetLon();
		lat = pos.GetLat();
	}

	public int getIcon() {
		return icon;
	}

	public void setIcon(int icon) {
		this.icon = icon;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public String getPhoneNum() {
		return phoneNum;
	}

	public void setPhoneNum(String phoneNum) {
		this.phoneNum = phoneNum;
	}

	public String getNote() {
		return note;
	}

	public void setNote(String note) {
		this.note = note;
	}

	public String getSound() {
		String strName = new String();
		strName = String.format( "/sound/sound%d.wav", sound);
		return Start.RUNDIR + strName;
	}

	public int getSoundInt() {
		return sound;
	}

	public void setSoundInt(int nsound) {
		sound = nsound;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;

		FavoriteData other = (FavoriteData) obj;

		if (Double.doubleToLongBits(lat) != Double.doubleToLongBits(other.lat))
			return false;
		if (Double.doubleToLongBits(lon) != Double.doubleToLongBits(other.lon))
			return false;
		
		
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;	
		
		if (strExInfo == null) {
			if (other.strExInfo != null)
				return false;
		} else if (!strExInfo.equals(other.strExInfo))
			return false;	
	
		return true;
	}

	public long currentTimeMillis() {
		return currentTimeMillis;
	}

	public void setCurrentTimeMillis(long currentTimeMillis) {
		this.currentTimeMillis = currentTimeMillis;
	}
	
	public void setExInfo(String str) {
		this.strExInfo = str;
	}
	
	public String getExInfo() {
		return strExInfo;
	}
	
	public String getDataTime(){
		SimpleDateFormat formatter = new SimpleDateFormat(
				"yyyy-M-dd HH:mm:ss");
		Date curDate = new Date(currentTimeMillis);
		String res = formatter.format(curDate);
		return res;
	}
}
